package com.mall.service.commodity.controller;

import com.mall.autoconfig.interceptor.BaseContext;
import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.CmsSubjectProductRelation;
import com.mall.model.domain.PmsProduct;
import com.mall.model.dto.ProductListDto;
import com.mall.model.dto.ProductcreateDto;
import com.mall.service.commodity.service.PmsProductService;
import org.bouncycastle.pqc.crypto.newhope.NHOtherInfoGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PmsProductController
 * @Description 商品表现层
 * @Author dcq
 * @Date 2023/3/13 9:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/product")
public class PmsProductController {
    @Autowired
    private PmsProductService pmsProductService;
    //根据商品名称或货号模糊查询
    @GetMapping("/simpleList")
    public CommonResult<PmsProduct> simpleList(String keyword){
       PmsProduct pmsProduct= pmsProductService.simpleListSei(keyword);
       return CommonResult.success(pmsProduct);
    }

    //查询商品
    @GetMapping("/list")
    public CommonResult<CommonPage>list(ProductListDto dto, @RequestParam(defaultValue="1")Integer pageNum,
                                        @RequestParam(defaultValue = "10")Integer pageSize){

         CommonPage page =pmsProductService.list(pageNum,pageSize,dto);
         return CommonResult.success(page);
    }
    //创建商品
      @PostMapping("/create")
      public CommonResult ctrate(@RequestBody ProductcreateDto dto){
             pmsProductService.createSei(dto);
             return  CommonResult.success("添加成功");
      }
    //批量修改删除状态
    @PostMapping("/update/deleteStatus")
    public CommonResult deleteStatus(Integer []ids,Integer deleteStatus){
       pmsProductService.deleteStatusSei(ids,deleteStatus);
       return  CommonResult.success("删除成功");
    }
    //批量设为新品
    @PostMapping("/update/newStatus")
    public  CommonResult newStatus(Integer[]ids,Integer newStatus){
        pmsProductService.newStatusSei(ids,newStatus);
        return  CommonResult.success("修改成功");
    }
    //批量上下架商品
    @PostMapping("/update/publishStatus")
    public CommonResult publishStatus(Integer[]ids,Integer publishStatus){
       pmsProductService.publishStatusSei(ids,publishStatus);
        return  CommonResult.success("修改成功");    }
    //批量推荐商品
    @PostMapping("/update/recommendStatus")
    public CommonResult  recommendStatus(Integer[]ids,Integer recommendStatus ){
        pmsProductService.recommendStatusSei(ids,recommendStatus);
        return  CommonResult.success("修改成功");

    }
    //批量修改审核状态
    @PostMapping("/update/verifyStatus")
    public CommonResult  verifyStatus(Integer[]ids,Integer verifyStatus,String  detail ){
        String currentId = BaseContext.getCurrentId();
        pmsProductService.verifyStatusSei(ids,verifyStatus ,detail, currentId);
        return  CommonResult.success("修改成功");
    }
    //更新商品
    @PostMapping("/update/{id}")
    public CommonResult update(@RequestBody ProductcreateDto dto,@PathVariable Integer id){
        pmsProductService.updateSei(dto,id);
        return  CommonResult.success("修改成功");
    }
    //根据商品id获取商品编辑信息 回显
    @GetMapping("/updateInfo/{id}")
    public  CommonResult<ProductcreateDto> updateId(@PathVariable Integer id){
        ProductcreateDto dto= pmsProductService.updateIdSei(id);
        return CommonResult.success(dto);
    }
    //根据id查询商品
    @GetMapping("findId")
    public PmsProduct findId(Integer id){
        PmsProduct body=pmsProductService.getId(id);
        return body;
    }
}